package com.sgcc.manager.sql.util;

import java.io.Serializable;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
* Session获取属性工具类
* 
*/
public abstract class SessionUtil {
	public static Serializable get(HttpServletRequest req, String name) {
		HttpSession session = req.getSession(false);
		if (session != null) {
			return (Serializable) session.getAttribute(name);
		} else {
			return null;
		}
	}

	public static void set(HttpServletRequest req,String name, Serializable value) {
		HttpSession session = req.getSession();
		session.setAttribute(name, value);
	}

	public static String getId(HttpServletRequest req) {
		return req.getSession().getId();
	}

	public static void logout(HttpServletRequest req) {
		HttpSession session = req.getSession(false);
		if (session != null) {
			session.invalidate();
		}
	}

	public static void remove(HttpServletRequest req,String name) {
		HttpSession session=req.getSession(false);
		if(session!=null)
			session.removeAttribute(name);
	}
}

